<?php
/* --- Add class of Ngoc --- */
function unFormatDate($d=null , $f="d-m-Y h:i:s"){
	$d=($d?$d:date("Y-m-d h:i:s"));
  return date($f,strtotime($d));
}

function formatDate($d=null){
	$arr = explode('-',$d);
	return $arr[2]."-".$arr[1]."-".$arr[0];
}

//Change name and resize images
function get_new_file_name($old_name,$prefix)
{
	$ext=strstr($old_name,".");
	return $prefix.$ext;
}

//Resize Image
function Resize_File($file, $directory, $max_width = 0, $max_height = 0)
{
	global $config;
	
	$full_file = $directory.$file;
	
	if (eregi("\.png$", $full_file))
	{
	$img = imagecreatefrompng($full_file);
	}
	
	if (eregi("\.(jpg|jpeg)$", $full_file))
	{
	$img = imagecreatefromjpeg($full_file);
	}
	
	if (eregi("\.gif$", $full_file))
	{
	$img = imagecreatefromgif($full_file);
	}
	
	$FullImage_width = imagesx($img);
	$FullImage_height = imagesy($img);
	
	if (isset($max_width) && isset($max_height) && $max_width != 0 && $max_height != 0)
	{
	$new_width = $max_width;
	$new_height = $max_height;
	}
	elseif (isset($max_width) && $max_width != 0)
	{
	$new_width = $max_width;
	$new_height = ((int)($new_width * $FullImage_height) / $FullImage_width);
	}
	elseif (isset($max_height) && $max_height != 0)
	{
	$new_height = $max_height;
	$new_width = ((int)($new_height * $FullImage_width) / $FullImage_height);
	}
	else
	{
	$new_height = $FullImage_height;
	$new_width = $FullImage_width;
	}
	
	$full_id = imagecreatetruecolor($new_width, $new_height);
	imagecopyresampled($full_id, $img, 0, 0, 0, 0, $new_width, $new_height, $FullImage_width, $FullImage_height);
	
	
	if (eregi("\.(jpg|jpeg)$", $full_file))
	{
	$full = imagejpeg($full_id, $full_file, 100);
	}
	
	if (eregi("\.png$", $full_file))
	{
	$full = imagepng($full_id, $full_file);
	}
	
	if (eregi("\.gif$", $full_file))
	{
	$full = imagegif($full_id, $full_file);
	}
	
	imagedestroy($full_id);
	unset($max_width);
	unset($max_height);
}
//Replace ky tu co dau sang ko dau
function RemoveSign($str)
{
$coDau=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă","ằ","ắ"
				,"ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề","ế","ệ","ể","ễ","ì","í","ị","ỉ","ĩ",
				"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
				,"ờ","ớ","ợ","ở","ỡ",
				"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
				"ỳ","ý","ỵ","ỷ","ỹ",
				"đ",
				"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
				,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
				"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
				"Ì","Í","Ị","Ỉ","Ĩ",
				"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
				,"Ờ","Ớ","Ợ","Ở","Ỡ",
				"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
				"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
				"Đ","ê","ù","à",".","'","(",")");
$khongDau=array("a","a","a","a","a","a","a","a","a","a","a"
				,"a","a","a","a","a","a",
				"e","e","e","e","e","e","e","e","e","e","e",
				"i","i","i","i","i",
				"o","o","o","o","o","o","o","o","o","o","o","o"
				,"o","o","o","o","o",
				"u","u","u","u","u","u","u","u","u","u","u",
				"y","y","y","y","y",
				"d",
				"A","A","A","A","A","A","A","A","A","A","A","A"
				,"A","A","A","A","A",
				"E","E","E","E","E","E","E","E","E","E","E",
				"I","I","I","I","I",
				"O","O","O","O","O","O","O","O","O","O","O","O"
				,"O","O","O","O","O",
				"U","U","U","U","U","U","U","U","U","U","U",
				"Y","Y","Y","Y","Y",
				"D","e","u","a","","","","");
return str_replace($coDau,$khongDau,$str);
}
//Replace HTML
function ReplaceHTML($str){
	$character 	= array('&nbsp;', '&lt;', '&gt;', '&amp;', '&quot;');
    $html		= array(' ', '<', '>', '&', '"');
    return str_replace($character, $html, $str);
}
function createRandString($num=5){
  $str = array_merge(range(0, 9), range(0, 9));
  $string = '';
  for ($i=0; $i<$num; $i++) {
   $string .= $str[rand(0, 35)];
  }
  return $string;
}

//upload and crop image
function resizeImage($image,$width,$height,$scale) {
	$newImageWidth = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	$source = imagecreatefromjpeg($image);
	imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
	imagejpeg($newImage,$image,90);
	chmod($image, 0777);
	return $image;
}
//You do not need to alter these functions
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
	$newImageWidth = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	$source = imagecreatefromjpeg($image);
	imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
	imagejpeg($newImage,$thumb_image_name,90);
	chmod($thumb_image_name, 0777);
	return $thumb_image_name;
}
//You do not need to alter these functions
function getHeight($image) {
	$sizes = getimagesize($image);
	$height = $sizes[1];
	return $height;
}
//You do not need to alter these functions
function getWidth($image) {
	$sizes = getimagesize($image);
	$width = $sizes[0];
	return $width;
}
//ngockv
?>